from django import forms
from models import Profile
import strings
from registration.forms import RegistrationForm
from django.forms.fields import ChoiceField


from django.contrib.localflavor.us.us_states import STATE_CHOICES
from django.contrib.localflavor.us.forms import USStateField
from django.contrib.localflavor.us.forms import USZipCodeField


from constants import VERMONT_COUNTIES
from constants import AGE_RANGES

from django.contrib.localflavor.us.forms import USPhoneNumberField

class UserRegistrationForm(RegistrationForm):

    first_name = forms.CharField(max_length = 50, label=u'First Name')    
    last_name = forms.CharField(max_length = 50, label=u'Last Name')
    address = forms.CharField(label=u'Address')
    city = forms.CharField(label=u'City')
    email = forms.CharField(label=u'Email')
    
    #Lamoille is the initial county
    volunteer_county1 = ChoiceField(label=u'County Choice 1', choices = VERMONT_COUNTIES, initial = '7')
    volunteer_county2 = ChoiceField(label=u'County Choice 2', choices = VERMONT_COUNTIES, initial = '7')
    volunteer_county3 = ChoiceField(label=u'County Choice 3', choices = VERMONT_COUNTIES, initial = '7')
    
    agerange = ChoiceField(label=u'AgeRange', choices = AGE_RANGES, initial = '1')
    phone = USPhoneNumberField(label=u'Phone (XXX-XXX-XXXX)')
    emergency_contact_first_name = forms.CharField(max_length = 50, label=u'Emergency Contact First Name')    
    emergency_contact_last_name = forms.CharField(max_length = 50, label=u'Emergency Contact Last Name')
    emergency_contact_phone = USPhoneNumberField(label=u'Emerg. Cont. Phone (XXX-XXX-XXXX)')
    emergency_contact_relationship = forms.CharField(max_length = 50, label=u'Emergency Contact Relationship')   
    
    
    #state = USStateField(widget=forms.Select(list(STATE_CHOICES)), default='Vermont')
    #LIST_STATE_CHOICES = list(STATE_CHOICES)
    #LIST_STATE_CHOICES.insert(0, ('', '---------'))
    #state = USStateField(widget=forms.Select(choices=LIST_STATE_CHOICES), initial='VT')
    
    # Reordering the fields, see discussion at http://stackoverflow.com/questions/913589/django-forms-inheritance-and-order-of-form-fields
    def __init__(self, *args, **kwargs):
        super(RegistrationForm, self).__init__(*args, **kwargs)
        self.fields.keyOrder = ['first_name', 'last_name', 'address', 'city', 'volunteer_county1',  'volunteer_county2', 'volunteer_county3', 
                                                'agerange', 'phone', 'username', 'email', 'password1', 'password2', 'emergency_contact_first_name', 
                                                'emergency_contact_last_name', 'emergency_contact_phone', 'emergency_contact_relationship']
